<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html>
<head>
   	<title>${fns:getConfig('productName')}</title>
    <meta name="decorator" content="blank"/>
	<%@include file="/WEB-INF/view/include/comfile.jsp" %>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <!-- <script>if(window.top !== window.self){ window.top.location = window.location;}</script> -->
	
	<%@include file="/WEB-INF/view/include/jqGrid.jsp" %>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
						<div class="col-sm-8 btn-group wrapper-l-xs">
							<a id="addPage" href="${ctx}/sys/user/form" class="btn btn-default btn-sm"><i class="fa fa-plus"></i> 添    加 </a>
						</div>
						<div class="col-sm-4  wrapper-r-xs8 ">
							<div class="pull-right btn-group ">
								<a id="updatePage" onclick="javascript:void(0)" class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i> 编辑 </a>
								<a id="delPage" onclick="javascript:void(0)" class="btn btn-danger btn-sm"><i class="fa fa-times"></i> 删除 </a>
							</div>
						</div>
                    </div>
                    <div class="ibox-content b-none">
                        <div class="jqGrid_wrapper">
                            <table id="table_list_1"></table>
                            <div id="pager_list_1"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        $(document).ready(function(){
			$.jgrid.defaults.styleUI="Bootstrap";

			$("#table_list_1").jqGrid({
				 url:'http://localhost:8888/base-admin/a/sys/user/list',
				 datatype:"json",
				 mtype : "post",
				 height:400,
				 autowidth:true,
				 shrinkToFit:true,
				 rowNum:10,
				 rowList:[10,20,50],
				 //multiselect:true,
				 //multiboxonly:false,
				 //multiselectWidth:60,
				 //toolbar:[true,"bottom"],
				 colNames:["账号","邮箱","电话","手机","最近登录","备注"],
				 colModel:[
						    {name:"loginName",index:"loginName",width:120},
						    {name:"email",index:"email",width:140},
						    {name:"phone",index:"phone",width:120},
						    {name:"mobile",index:"mobile",width:120},
						    {name:"loginData",index:"loginData",width:150},
						    {name:"remarks",index:"remarks",width:200}
						  ],
				 pager:"#pager_list_1",
				 viewrecords:true,
				 //caption:"用户列表", 			  
				 hidegrid:false
				 
				 /* onSelectRow: function(id){   
					 $.ajax({
						  url: 'http://localhost:8888/base-admin/a/sys/user/list',
						  contentType: 'application/json',
						  dataType: 'json',
						  success: function (data) {
						      console.log(data);
						  },
						  error: function (jqXHR, text, errorThrown) {
						      console.log(jqXHR + " " + text + " " + errorThrown);
						  }
					})	
				 } */
			 });
			
			
			$("#delPage").click(function() {
			    var gr = jQuery("#table_list_1").jqGrid('getGridParam','selrow');
			    
			    if(gr==null){
			    	layer.msg('未选择操作元素!',{
			    		offset: 't',
			    		anim: 6
			    	});
			    }else{
			    	layer.confirm('确认删除元素:'+gr, {
			    		   title: false, //不显示标题栏
					       offset: ['30%', '40%'],
					       btn: ['确认','取消'] //按钮
				    	}, function(){
				    		$.ajax({
								  url: '${ctx}/sys/user/del',
								  dataType: 'json',
								  type: 'POST',
								  data:{
									  id:gr
								  },
								  success: function (data) {
									  jQuery("#table_list_1").trigger("reloadGrid");
								  },
								  error: function (jqXHR, text, errorThrown) {
								      console.log(jqXHR + " " + text + " " + errorThrown);
								  }
							});
						  layer.closeAll();
				    	}, function(){
				    		closeBtn: 0;
				    	});
			    }
			    
		    });
			
			$("#updatePage").click(function() {
			    var gr = jQuery("#table_list_1").jqGrid('getGridParam','selrow');
			    
			    if(gr==null){
			    	layer.msg('未选择操作元素!',{
			    		offset: 't',
			    		anim: 6
			    	});
			    }else{
			    	location="${ctx}/sys/user/form?id="+gr;
			    }
		    });
			
			$(window).bind("resize",function(){
				var width=$(".jqGrid_wrapper").width();
				$("#table_list_1").setGridWidth(width)
			})
		});
    </script>
</body>
</html>
